/* Copyright (C) 2008  Romolo Camplani, Marco Fortunato, Marco Marelli, Guido Rota, Fabio A. Schreiber et al.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.dei.perla.parser.expressions;

import java.sql.Timestamp;



/**
 * Rappresenta un valore costante.
 * Permette di conoscerne il tipo di dato e di leggerne il valore
 * castandolo al tipo desiderato.
 */
public abstract class Constant {
	
	/**
	 * Restituisce true se il valore della costante e' NULL 
	 */
	public boolean isNull(){
		return false;
	}
	
	/**
	 * Restituisce TRUE se la classe estende ConstantDerived
	 * @return
	 */
	public boolean isUserDefined() {
		return false;
	}
	
	/**
	 * Casta il valore della costante a INTEGER 
	 */
	public int getValueInt() throws ConstantCastException {
		throw new ConstantCastException();
	}
	
	/**
	 * Casta il valore della costante a FLOAT
	 */
	public double getValueFloat() throws ConstantCastException {
		throw new ConstantCastException();
	}
	
	/**
	 * Casta il valore della costante a BOOLEAN
	 */
	public LogicValue getValueLogic() throws ConstantCastException {
		throw new ConstantCastException();
	}
	
	/**
	 * Casta il valore della costante a STRING 
	 */
	public String getValueString() throws ConstantCastException {
		throw new ConstantCastException();
	}
	
	/**
	 * Casta il valore della costante a ID 
	 */
	public String getValueID() throws ConstantCastException {
		throw new ConstantCastException();
	}
	
	/**
	 * Casta il valore della costante a Timestamp
	 */
	public long getValueTimestamp() throws ConstantCastException {
		throw new ConstantCastException();
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato dell'addizione
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public Constant addition(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation + not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> additionResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation + not supported with " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato della sottrazione
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public Constant subtraction(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation - not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> subtractionResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation - not supported with " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato della moltiplicazione
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public Constant multiplication(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation * not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> multiplicationResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation * not supported with " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato della divisione
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 * @throws DivisionByZeroException 
	 */
	public Constant division(Constant parConst) throws OperationNotSupportedException, ConstantCastException, DivisionByZeroException {
		throw new OperationNotSupportedException("Operation / not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> divisionResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation / not supported with " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto di uguaglianza
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isEqual(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation == not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto di disuguaglianza
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isUnequal(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation != not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto di maggiorita'
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isGreater(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation >= not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto di stretta maggiorita' (uguaglianza not inclusa)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isStrictlyGreater(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation > not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto di minorit�
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isMinor(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation <= not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto di stretta minorita' (uguaglianza not inclusa)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isStrictlyMinor(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation < not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic (o ConstantNull in alcuni casi) rispecchiante l'operazione AND
	 * tra la classe e l'oggetto parConst passaro come parametro.
	 */
	public ConstantLogic and(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation && not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic (o ConstantNull in alcuni casi) rispecchiante l'operazione OR
	 * tra la classe e l'oggetto parConst passaro come parametro.
	 */
	public ConstantLogic or(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation || not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic (o ConstantNull in alcuni casi) rispecchiante l'operazione XOR
	 * tra la classe e l'oggetto parConst passaro come parametro.
	 */
	public ConstantLogic xor(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation ^^ not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic (o ConstantNull in alcuni casi) rispecchiante l'operazione NOT
	 * sulla classe stessa.
	 */
	public ConstantLogic not() throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation ! not supported on " + this.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic (o ConstantNull in alcuni casi) rispecchiante l'operazione AND
	 * tra la classe e l'oggetto parConst passaro come parametro.
	 */
	public ConstantLogic andInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation && not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic (o ConstantNull in alcuni casi) rispecchiante l'operazione OR
	 * tra la classe e l'oggetto parConst passaro come parametro.
	 */
	public ConstantLogic orInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation || not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic (o ConstantNull in alcuni casi) rispecchiante l'operazione XOR
	 * tra la classe e l'oggetto parConst passaro come parametro.
	 */
	public ConstantLogic xorInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation ^^ not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato dell'addizione inversa (commutazione dei parametri)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public Constant additionInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation + not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato della sottrazione inversa (commutazione dei parametri)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public Constant subtractionInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation - not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato della moltiplicazione inversa (commutazione dei parametri)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public Constant multiplicationInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation * not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto Constant contenente il risultato della divisione inversa (commutazione dei parametri)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 * @throws DivisionByZeroException 
	 */
	public Constant divisionInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException, DivisionByZeroException {
		throw new OperationNotSupportedException("Operation / not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto invertito di maggiorita'
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isGreaterInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation >= not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto invertito di stretta maggiorita' (uguaglianza not inclusa)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isStrictlyGreaterInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation > not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto invertito di minorit�
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isMinorInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation <= not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	/**
	 * Restituisce un oggetto ConstantLogic contenente il risultato del confornto invertito di stretta minorita' (uguaglianza not inclusa)
	 * tra la costante stessa e l'oggetto Costant passato come parametro
	 */
	public ConstantLogic isStrictlyMinorInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation < not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public ConstantLogic isBetween(Constant parConstBegin, Constant parConstEnd) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation IS BETWEEN not supported between " + this.toString() + " and " + parConstBegin.toString() + " and " + parConstEnd.toString());
	}
	
	public Constant bitwiseAND(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation & not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> bitwiseANDResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation & not supported with " + parConst.toString());
	}
	
	public Constant bitwiseOR(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation | not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> bitwiseORResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation | not supported with " + parConst.toString());
	}
	
	public Constant bitwiseXOR(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation ^ not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> bitwiseXORResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation ^ not supported with " + parConst.toString());
	}
	
	public Constant bitwiseNOT() throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation ~ not supported on " + this.toString());
	}
	
	public static Class<? extends Object> bitwiseNOTResultType() throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation ~ not supported");
	}
	
	public Constant bitwiseRightShift(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation >> not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> bitwiseRightShiftResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation >> not supported with " + parConst.toString());
	}
	
	public Constant bitwiseLeftShift(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation << not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public static Class<? extends Object> bitwiseLeftShiftResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation << not supported with " + parConst.toString());
	}
	
	public Constant bitwiseANDInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation & not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public Constant bitwiseORInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation | not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public Constant bitwiseXORInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation ^ not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public Constant bitwiseRightShiftInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation >> not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public Constant bitwiseLeftShiftInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation << not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public ConstantLogic isLike(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation IS LIKE not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public ConstantLogic isLikeInverse(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation IS LIKE not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public ConstantLogic is(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation IS not supported between " + this.toString() + " and " + parConst.toString());
	}
	
	public Constant sign() throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation SIGN not supported by " + this.toString());
	}
	
	public static Class<? extends Object> signResultType() throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation SIGN not supported");
	}
	
	public static Class<? extends Object> additionInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation + not supported with " + parConst.toString());
	}

	public static Class<? extends Object> subtractionInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation - not supported with " + parConst.toString());
	}

	public static Class<? extends Object> multiplicationInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation * not supported with " + parConst.toString());
	}

	public static Class<? extends Object> divisionInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation / not supported with " + parConst.toString());
	}

	public static Class<? extends Object> bitwiseANDInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation & not supported with " + parConst.toString());
	}

	public static Class<? extends Object> bitwiseORInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation | not supported with " + parConst.toString());
	}

	public static Class<? extends Object> bitwiseXORInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation ^ not supported with " + parConst.toString());
	}

	public static Class<? extends Object> bitwiseRightShiftInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation >> not supported with " + parConst.toString());
	}

	public static Class<? extends Object> bitwiseLeftShiftInverseResultType(Class<? extends Constant> parConst) throws OperationNotSupportedException {
		throw new OperationNotSupportedException("Operation << not supported with " + parConst.toString());
	}

	public static boolean isEquallyComparable(Class<? extends Constant> parConst) {
		return false;
	}
	
	public static boolean isFullyComparable(Class<? extends Constant> parConst) {
		return false;
	}
	
	public static boolean isLikeComparable(Class<? extends Constant> parConst) {
		return false;
	}
	
	public static boolean isLikeInverseComparable(Class<? extends Constant> parConst) {
		return false;
	}
	
	/**
	 * Questo metodo si riferisce al confornto con il LogicalObjectAttribute
	 */
	public ConstantLogic exist(Constant parConst) throws OperationNotSupportedException, ConstantCastException {
		throw new OperationNotSupportedException("Operation not supported between " + this.toString() + " and " + parConst.toString());
	}

}
